<?php
/**
 * CEOfox
 *
 * @copyright  Copyright 2011-2012 CEOfox, Inc.
 * @license    http://ceofox.com/pages/license
 * @version    $Id: block.class.php 67082 2013-05-24 09:40:17 $
 * @author     CEOfox, Inc.
 */
?>
<?php
defined('PHPFOX') or exit('NO DICE!');
class Follow_Component_Controller_Block extends phpfox_component
{
    public function process()
    {
        Phpfox::isUser(true);
        $sMessage = '';
        $iId = $this->request()->get('id', false);
        $sType = $this->request()->get('type', false);
        $iItemId = $this->request()->get('oid', false);
        if($sType == 'user')
        {
            $sLink = 'follow';
        }
        elseif($sType == 'pages')
        {
            $sLink = 'pages.'.$iItemId.'.follow.follower';
        }
        if(!empty($iId) && !empty($sType) && !empty($iItemId))
        {
            if($iId == 'all')
            {
                if(Phpfox::getService('follow')->blockAll($iItemId, $sType))
                {
                    $sMessage = Phpfox::getPhrase('follow.block_all_successfully');        
                }
                else
                {
                    $sMessage = Phpfox::getPhrase('follow.there_are_some_errors_happen_when_perform_this_action'); 
                }
            }
            else
            {
                $bCheckInt = (int)$iId;
                if(md5($bCheckInt) == md5($iId))
                {
                    if(phpfox::getUserId() == $iItemId && $sType == 'user')
                    {
                        $sMessage = Phpfox::getPhrase('follow.you_can_not_block_yourself');      
                    }
                    if(Phpfox::getService('follow')->isUserExists($iId))
                    {
                        if(!Phpfox::getService('follow')->alreadyBlock($iItemId, $iId, $sType) && $iId > 0)
                        {
                            if(Phpfox::getService('follow')->blockUser($iItemId, $iId, $sType))
                            {
                                $sMessage = Phpfox::getPhrase('follow.block_follow_successfully');        
                            }
                            else
                            {
                                $sMessage = Phpfox::getPhrase('follow.there_are_some_errors_happen_when_block_this_user');
                            }
                            
                        }
                        else
                        {
                            $sMessage = Phpfox::getPhrase('follow.you_already_blocked_this_user');    
                        }    
                    }
                    else
                    {
                        $sMessage = Phpfox::getPhrase('follow.user_id_not_exists');
                    }
                }
                else
                {
                    $sMessage = Phpfox::getPhrase('follow.user_id_must_be_an_integer_number');   
                }
            }
        }
        else
        {
            $sMessage = Phpfox::getPhrase('follow.missing_information_for_perform_this_action');
        }  
        $this->url()->send($sLink, null, $sMessage);
    }
}
?>

